﻿using Ewelve_Mouth_HD.BLL;
using Ewelve_Mouth_HD.DAL;
using Ewelve_Mouth_HD.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Ewelve_Mouth_HD.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoomController : ControllerBase
    {
        private readonly RoomBll roomBll;
        private readonly ILogger<RoomController> _logger;

        public RoomController(RoomBll _roomBll, ILogger<RoomController> logger)
        {
            roomBll = _roomBll;
            _logger = logger;
        }
        /// <summary>
        /// 排房添加
        /// </summary>
        /// <param name="W"></param>
        /// <returns></returns>
        [HttpPost]
        public int RoomAdd(Room W)
        {
            try
            {
                return roomBll.RoomAdd(W);
            }
            catch (Exception)
            {
                _logger.LogInformation("排房添加错误");
                throw;
            }
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageSum"></param>
        /// <param name="PageCount"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult RoomShowAll(int PageIndex, int PageSize)
        {
            try
            {
                int PageSum = 0;
                int PageCount = 0;
                var list= roomBll.RoomShowAll(PageIndex, PageSize, out PageSum, out PageCount);
                return Ok(new {PageSum=PageSum,PageCount=PageCount,list=list });
            }
            catch (Exception)
            {
                _logger.LogInformation("排房显示错误");
                throw;
            }
        }
    }
}
